package com.knoya.chejian.pda.module.outsourcing

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import com.knoya.chejian.pda.R
import com.knoya.chejian.pda.util.Myutil
import kotlinx.android.synthetic.main.item_outsoursing.view.*

class OutSourcingAdapter(var context: Context,  var list: MutableList<String>) : BaseAdapter() {
    var minflater: LayoutInflater = LayoutInflater.from(context)
    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        var v :View
        var h : ViewHolder
        if(convertView==null){
            v = minflater.inflate(R.layout.item_outsoursing,null)
            h = ViewHolder(v)
            v.tag=h
        }else{
            v = convertView
            h = v.tag as ViewHolder
        }
        Myutil.settv(list[position],h.TvOutsoursing)
        h.BtOutsoursing.setOnClickListener { remove(position) }

        return v
    }

    override fun getItem(position: Int): Any {
        return list[position]
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getCount(): Int {
        return  list.size
    }
    class ViewHolder(var v : View){
        //        var titletextview = v.dragsort_listview_item_textview
        var TvOutsoursing = v.TvOutsoursing
        var BtOutsoursing = v.BtOutsoursing
    }

    fun remove(arg0: Int) {// 删除指定位置的item
        list.removeAt(arg0)
        this.notifyDataSetChanged()
    }
}